﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using biolit_config;
using System.Text.RegularExpressions;

namespace UCSD_BioLit
{
    public partial class DownloadsSettings : Form
    {
        public DownloadsSettings()
        {
            InitializeComponent();
        }

        private void DownloadsSettings_Load(object sender, EventArgs e)
        {
            ConfigSettings cs = Biolit_Settings.Settings;
            if (cs.downloadsSettings.Equals(0))
                txtDownloads.Text = "10";
            else
                txtDownloads.Text = cs.downloadsSettings.ToString();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if(!Regex.IsMatch(txtDownloads.Text.Trim(), @"^\d+$"))
            {
                MessageBox.Show("Please enter a Valid Number");
                txtDownloads.Text = string.Empty;
            }
            else
            {
                try
                {
                    ConfigSettings cs = Biolit_Settings.Settings;
                    cs.downloadsSettings = Convert.ToInt32(txtDownloads.Text.Trim());
                    Biolit_Settings.StoreSettings();
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error while processing data");
                    this.Close();
                }
            }

        }
    }
}
